import $ from "jquery";
import {url} from "../../util/config";
import {closeStatus, openStatus} from "../../store/action";
import {success,error as exception} from '../../util/responseStatus'
import {message} from "antd";
import login from "../login";

function getNewLogin(items) {
    return deleteLinks(items)
}

export default function deleteLinks(items) {
    //items為數組，元素的值是：linkId
    console.log(items)
    let token = localStorage.getItem("token")

    let status = null
    $.ajax({
        async:false,
        headers: {
            'Accept': "application/json",
            'Authorization': token
        },
        url: url.api_url+`LinkManage/DelLinks`,
        type: 'POST',
        contentType:"application/json",
        data: JSON.stringify({
            LINKS_ARR:items
        }),
        success: function (result) {
            status=result.result
            if(status=="Token過期請重新登錄") {
                login(localStorage.getItem("account"), localStorage.getItem("password"));
                status = getNewLogin(items)
            }else {
                if(status=="ok"){
                    message.success("删除成功");
                }else message.error("删除失败")
            }
        },
        error:function (error) {
            status="error";
            message.error("请求异常")
        }
    })

    return status;

//  写ajax时把上面注释取消
//     success();
//     return 'ok';
}
